home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / C++ CDEV ƒ / UStandAlone.cp < prev    next >
Encoding:
Text File  |  1991-08-24  |  1.1 KB  |  59 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    UStandAlone.cp
  3.  *    based on A5World.cp by Patrick Beard, ©1990 by Patrick C. Beard.  All rights reserved.
  4.  *    
  5.  *    KNOWN BUGS AND SHORTCOMINGS:
  6.  *        [none]
  7.  */
  8.  
  9. #ifndef __OSUTILS__
  10. #include <OSUtils.h>
  11. #endif
  12.  
  13. #ifndef __USTANDALONE__
  14. #include <UStandAlone.h>
  15. #endif
  16.  
  17. const long kAppParmsSize = 32;
  18.  
  19. extern "C" {
  20. void A5Init(A5Reference);
  21. long A5Size(void);
  22. void init_vtbls(void);
  23. }
  24.  
  25. inline A5Reference SetA5(A5Reference newA5) {                                                // trivial overloading to avoid typecasting in code
  26.     return (A5Reference)SetA5((long)newA5);
  27. }
  28.  
  29. TStandAloneWorld::TStandAloneWorld(Boolean codeFloats):
  30.     fA5WorldSize(A5Size()), fCodeFloats(codeFloats), fTheirA5(nil) {
  31.     (void)LockHigh();
  32.     if (fOurA5 = NewPtr(fA5WorldSize)) {
  33.         A5Init(fOurA5 + fA5WorldSize - kAppParmsSize);
  34.         Enter();
  35.         if (!fCodeFloats)
  36.             init_vtbls();
  37.         Leave();
  38.     }
  39.     Unlock();
  40. }
  41.  
  42. TStandAloneWorld::~TStandAloneWorld() {
  43.     Leave();
  44.     if (fOurA5)
  45.         DisposPtr(fOurA5);
  46. }
  47.  
  48. void TStandAloneWorld::Enter() {
  49.     fTheirA5 = SetA5(fOurA5 + fA5WorldSize - kAppParmsSize);
  50.     if (fCodeFloats)
  51.         init_vtbls();
  52. }
  53.  
  54. void TStandAloneWorld::Leave() {
  55.     if (fTheirA5) {
  56.         (void)SetA5(fTheirA5);
  57.         fTheirA5 = nil;
  58.     }
  59. }